Skip to content

Conversation

@jperezish
Copy link

This was a little tougher than I was anticipating. Having a better understanding of the current implementation definitely helps.

lib/match.rb Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you're looping over something to collect items into an array, I'd rather you use map.

@turns = 13.times.map do |x|
  turn = Turn.new(@opponent_a.strike, @opponent_b.strike)
  if @opponent_a.strike == turn.winner
    @opponent_a
  else
    @opponent_b
  end
end

@turns.each_with_index do |winner, i|
  puts "#{winner.name} won round #{i+1}!"
end

I also separated the running of the turns with the reporting of the turns.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. So in this case I'm interested in getting an array of winners for a given round. map returns an array so it more directly conveys what I intend to receive. Whereas in my implementation, I went in a round about way to get there by separately instantiating an array then using an iterator to populate that array. Is this a good way to look at it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep exactly. 😃

@jwo
Copy link
Member

jwo commented Jan 8, 2014

Nice submission -- let me know if you have any questions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants